from ckeditor_uploader.fields import RichTextUploadingField
from django.db import models

from flowers.base import BaseModel


class Tag(BaseModel):
    name = models.CharField("名称", max_length=20)

    class Meta:
        verbose_name = verbose_name_plural = "标签"

    def __str__(self):
        return self.name


class Article(BaseModel):
    title = models.CharField("标题", max_length=64)
    slug = models.CharField(max_length=128, db_index=True)
    tags = models.ManyToManyField(Tag, verbose_name="标签", blank=True)
    summary = models.CharField("摘要", max_length=128, null=True, blank=True)
    content = RichTextUploadingField("内容")
    published = models.BooleanField("是否已发布", default=False)
    published_at = models.DateTimeField("发布日期", null=True, editable=False)

    class Meta:
        verbose_name = verbose_name_plural = "文章"

    def __str__(self):
        return self.title
